home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DJLSR106.ARJ / SBUFVSCA.CC < prev    next >
C/C++ Source or Header  |  1992-03-29  |  17KB  |  732 lines

  1. /*
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  */
  17.  
  18. // Extensively hacked for GNU iostream by Per Bothner 1991, 1992.
  19. // Changes copyright Per Bothner 1992.
  20.  
  21. #if defined(LIBC_SCCS) && !defined(lint)
  22. static char sccsid[] = "%W% (Berkeley) %G%";
  23. #endif /* LIBC_SCCS and not lint */
  24.  
  25. #include <ioprivate.h>
  26. #include <ctype.h>
  27. #ifndef NO_STDARG
  28. #include <stdarg.h>
  29. #else
  30. #include <varargs.h>
  31. #endif
  32.  
  33. #ifdef sun /* SunOS incorrectly defines size_t to be int. */
  34. #define hardway
  35. #endif
  36.  
  37. #ifndef    NO_FLOATING_POINT
  38. #define FLOATING_POINT
  39. #endif
  40.  
  41. #ifdef FLOATING_POINT
  42. #include "floatio.h"
  43. #define    BUF    (MAXEXP+MAXFRACT+3)    /* 3 = sign + decimal point + NUL */
  44. #else
  45. #define    BUF    40
  46. #endif
  47.  
  48. /*
  49.  * Flags used during conversion.
  50.  */
  51. #define    LONG        0x01    /* l: long or double */
  52. #define    LONGDBL        0x02    /* L: long double; unimplemented */
  53. #define    SHORT        0x04    /* h: short */
  54. #define    SUPPRESS    0x08    /* suppress assignment */
  55. #define    POINTER        0x10    /* weird %p pointer (`fake hex') */
  56. #define    NOSKIP        0x20    /* do not skip blanks */
  57.  
  58. /*
  59.  * The following are used in numeric conversions only:
  60.  * SIGNOK, NDIGITS, DPTOK, and EXPOK are for floating point;
  61.  * SIGNOK, NDIGITS, PFXOK, and NZDIGITS are for integral.
  62.  */
  63. #define    SIGNOK        0x40    /* +/- is (still) legal */
  64. #define    NDIGITS        0x80    /* no digits detected */
  65.  
  66. #define    DPTOK        0x100    /* (float) decimal point is still legal */
  67. #define    EXPOK        0x200    /* (float) exponent (e+3, etc) still legal */
  68.  
  69. #define    PFXOK        0x100    /* 0x prefix is (still) legal */
  70. #define    NZDIGITS    0x200    /* no zero digits detected */
  71.  
  72. /*
  73.  * Conversion types.
  74.  */
  75. #define    CT_CHAR        0    /* %c conversion */
  76. #define    CT_CCL        1    /* %[...] conversion */
  77. #define    CT_STRING    2    /* %s conversion */
  78. #define    CT_INT        3    /* integer, i.e., strtol or strtoul */
  79. #define    CT_FLOAT    4    /* floating, i.e., strtod */
  80.  
  81. #define u_char unsigned char
  82. #define u_long unsigned long
  83.  
  84. extern "C" u_long strtoul(const char*, char**, int);
  85. static u_char *__sccl(register char *tab, register u_char *fmt);
  86.  
  87. int streambuf::vscan(char const *fmt0, _G_va_list args)
  88. {
  89.         va_list ap = (va_list)args;
  90.     register u_char *fmt = (u_char *)fmt0;
  91.     register int c;        /* character from format, or conversion */
  92.     register size_t width;    /* field width, or 0 */
  93.     register char *p;    /* points into all kinds of strings */
  94.     register int n;        /* handy integer */
  95.     register int flags;    /* flags as defined above */
  96.     register char *p0;    /* saves original value of p when necessary */
  97.     int nassigned;        /* number of fields assigned */
  98.     int nread;        /* number of characters consumed from fp */
  99.     // Assignments to base and ccfn are just to suppress warnings from gcc.
  100.     int base = 0;        /* base argument to strtol/strtoul */
  101.     u_long (*ccfn)(const char*, char**, int) = 0;
  102.     // conversion function (strtol/strtoul)
  103.     char ccltab[256];    /* character class table for %[...] */
  104.     char buf[BUF];        /* buffer for numeric conversions */
  105.  
  106.     /* `basefix' is used to avoid `if' tests in the integer scanner */
  107.     static short basefix[17] =
  108.         { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
  109.  
  110.     nassigned = 0;
  111.     nread = 0;
  112.     for (;;) {
  113.         c = *fmt++;
  114.         if (c == 0)
  115.             return (nassigned);
  116.         if (isspace(c)) {
  117.             for (;;) {
  118.                     c = sbumpc();
  119.                 if (c == EOF)
  120.                     return nassigned;
  121.                 if (!isspace(c)) {
  122.                     sputbackc(c);
  123.                     break;
  124.                 }
  125.                 nread++;
  126.             }
  127.             continue;
  128.         }
  129.         if (c != '%')
  130.             goto literal;
  131.         width = 0;
  132.         flags = 0;
  133.         /*
  134.          * switch on the format.  continue if done;
  135.          * break once format type is derived.
  136.          */
  137. again:        c = *fmt++;
  138.         switch (c) {
  139.         case '%':
  140. literal:
  141.                 n = sbumpc();
  142.             if (n == EOF)
  143.                 goto input_failure;
  144.             if (n != c) {
  145.                 sputbackc(n);
  146.                 goto match_failure;
  147.             }
  148.             nread++;
  149.             continue;
  150.  
  151.         case '*':
  152.             flags |= SUPPRESS;
  153.             goto again;
  154.         case 'l':
  155.             flags |= LONG;
  156.             goto again;
  157.         case 'L':
  158.             flags |= LONGDBL;
  159.             goto again;
  160.         case 'h':
  161.             flags |= SHORT;
  162.             goto again;
  163.  
  164.         case '0': case '1': case '2': case '3': case '4':
  165.         case '5': case '6': case '7': case '8': case '9':
  166.             width = width * 10 + c - '0';
  167.             goto again;
  168.  
  169.         /*
  170.          * Conversions.
  171.          * Those marked `compat' are for 4.[123]BSD compatibility.
  172.          *
  173.          * (According to ANSI, E and X formats are supposed
  174.          * to the same as e and x.  Sorry about that.)
  175.          */
  176.         case 'D':    /* compat */
  177.             flags |= LONG;
  178.             /* FALLTHROUGH */
  179.         case 'd':
  180.             c = CT_INT;
  181.             ccfn = (u_long (*)(const char, char**, int))strtol;
  182.             base = 10;
  183.             break;
  184.  
  185.         case 'i':
  186.             c = CT_INT;
  187.             ccfn = (u_long (*)(const char, char**, int))strtol;
  188.             base = 0;
  189.             break;
  190.  
  191.         case 'O':    /* compat */
  192.             flags |= LONG;
  193.             /* FALLTHROUGH */
  194.         case 'o':
  195.             c = CT_INT;
  196.             ccfn = strtoul;
  197.             base = 8;
  198.             break;
  199.  
  200.         case 'u':
  201.             c = CT_INT;
  202.             ccfn = strtoul;
  203.             base = 10;
  204.             break;
  205.  
  206.         case 'X':    /* compat   XXX */
  207.             flags |= LONG;
  208.             /* FALLTHROUGH */
  209.         case 'x':
  210.             flags |= PFXOK;    /* enable 0x prefixing */
  211.             c = CT_INT;
  212.             ccfn = strtoul;
  213.             base = 16;
  214.             break;
  215.  
  216. #ifdef FLOATING_POINT
  217.         case 'E':    /* compat   XXX */
  218.         case 'F':    /* compat */
  219.             flags |= LONG;
  220.             /* FALLTHROUGH */
  221.         case 'e': case 'f': case 'g':
  222.             c = CT_FLOAT;
  223.             break;
  224. #endif
  225.  
  226.         case 's':
  227.             c = CT_STRING;
  228.             break;
  229.  
  230.         case '[':
  231.             fmt = __sccl(ccltab, fmt);
  232.             flags |= NOSKIP;
  233.             c = CT_CCL;
  234.             break;
  235.  
  236.         case 'c':
  237.             flags |= NOSKIP;
  238.             c = CT_CHAR;
  239.             break;
  240.  
  241.         case 'p':    /* pointer format is like hex */
  242.             flags |= POINTER | PFXOK;
  243.             c = CT_INT;
  244.             ccfn = strtoul;
  245.             base = 16;
  246.             break;
  247.  
  248.         case 'n':
  249.             if (flags & SUPPRESS)    /* ??? */
  250.                 continue;
  251.             if (flags & SHORT)
  252.                 *va_arg(ap, short *) = nread;
  253.             else if (flags & LONG)
  254.                 *va_arg(ap, long *) = nread;
  255.             else
  256.                 *va_arg(ap, int *) = nread;
  257.             continue;
  258.  
  259.         /*
  260.          * Disgusting backwards compatibility hacks.    XXX
  261.          */
  262.         case '\0':    /* compat */
  263.             return (EOF);
  264.  
  265.         default:    /* compat */
  266.             if (isupper(c))
  267.                 flags |= LONG;
  268.             c = CT_INT;
  269.             ccfn = (u_long (*)(const char, char**, int))strtol;
  270.             base = 10;
  271.             break;
  272.         }
  273.  
  274.         /*
  275.          * We have a conversion that requires input.
  276.          */
  277.         if (sgetc() == EOF)
  278.             goto input_failure;
  279.  
  280.         /*
  281.          * Consume leading white space, except for formats
  282.          * that suppress this.
  283.          */
  284.         if ((flags & NOSKIP) == 0) {
  285.             n = *_gptr;
  286.             while (isspace(n)) {
  287.             _gptr++;
  288.             nread++;
  289.             n = sgetc();
  290.             if (n == EOF)
  291.                 goto input_failure;
  292.             }
  293.             // Note that there is at least one character in
  294.             // the buffer, so conversions that do not set NOSKIP
  295.             // can no longer result in an input failure.
  296.         }
  297.  
  298.         /*
  299.          * Do the conversion.
  300.          */
  301.         switch (c) {
  302.  
  303.         case CT_CHAR:
  304.             /* scan arbitrary characters (sets NOSKIP) */
  305.             if (width == 0)
  306.                 width = 1;
  307.             if (flags & SUPPRESS) {
  308.                 size_t sum = 0;
  309.                 for (;;) {
  310.                 if ((n = _egptr - _gptr) < (int)width) {
  311.                     sum += n;
  312.                     width -= n;
  313.                     _gptr += n;
  314.                     if (underflow() == EOF)
  315.                     if (sum == 0)
  316.                         goto input_failure;
  317.                     else
  318.                         break;
  319.                 } else {
  320.                     sum += width;
  321.                     _gptr += width;
  322.                     break;
  323.                 }
  324.                 }
  325.                 nread += sum;
  326.             } else {
  327.                 size_t r = sgetn((char*)va_arg(ap, char*),
  328.                          width);
  329.                 if (r == 0)
  330.                 goto input_failure;
  331.                 nread += r;
  332.                 nassigned++;
  333.             }
  334.             break;
  335.  
  336.         case CT_CCL:
  337.             /* scan a (nonempty) character class (sets NOSKIP) */
  338.             if (width == 0)
  339.                 width = ~0;    /* `infinity' */
  340.             /* take only those things in the class */
  341.             if (flags & SUPPRESS) {
  342.                 n = 0;
  343.                 while (ccltab[*_gptr]) {
  344.                     n++, _gptr++;
  345.                     if (--width == 0)
  346.                     break;
  347.                     if (sgetc() == EOF) {
  348.                     if (n == 0)
  349.                         goto input_failure;
  350.                     break;
  351.                     }
  352.                 }
  353.                 if (n == 0)
  354.                     goto match_failure;
  355.             } else {
  356.                 p0 = p = va_arg(ap, char *);
  357.                 while (ccltab[*_gptr]) {
  358.                 *p++ = *_gptr++;
  359.                 if (--width == 0)
  360.                     break;
  361.                 if (sgetc() == EOF)
  362.                     if (p == p0) {
  363.                     goto input_failure;
  364.                     break;
  365.                     }
  366.                 }
  367.                 n = p - p0;
  368.                 if (n == 0)
  369.                 goto match_failure;
  370.                 *p = 0;
  371.                 nassigned++;
  372.             }
  373.             nread += n;
  374.             break;
  375.  
  376.         case CT_STRING:
  377.             /* like CCL, but zero-length string OK, & no NOSKIP */
  378.             if (width == 0)
  379.                 width = ~0;
  380.             if (flags & SUPPRESS) {
  381.                 n = 0;
  382.                 while (!isspace(*_gptr)) {
  383.                     n++, _gptr++;
  384.                     if (--width == 0)
  385.                         break;
  386.                     if (sgetc() == EOF)
  387.                         break;
  388.                 }
  389.                 nread += n;
  390.             } else {
  391.                 p0 = p = va_arg(ap, char *);
  392.                 while (!isspace(*_gptr)) {
  393.                     *p++ = *_gptr++;
  394.                     if (--width == 0)
  395.                         break;
  396.                     if (sgetc() == EOF)
  397.                         break;
  398.                 }
  399.                 *p = 0;
  400.                 nread += p - p0;
  401.                 nassigned++;
  402.             }
  403.             continue;
  404.  
  405.         case CT_INT:
  406.             /* scan an integer as if by strtol/strtoul */
  407. #ifdef hardway
  408.             if (width == 0 || width > sizeof(buf) - 1)
  409.                 width = sizeof(buf) - 1;
  410. #else
  411.             /* size_t is unsigned, hence this optimisation */
  412.             if (--width > sizeof(buf) - 2)
  413.                 width = sizeof(buf) - 2;
  414.             width++;
  415. #endif
  416.             flags |= SIGNOK | NDIGITS | NZDIGITS;
  417.             for (p = buf; width; width--) {
  418.                 c = *_gptr;
  419.                 /*
  420.                  * Switch on the character; `goto ok'
  421.                  * if we accept it as a part of number.
  422.                  */
  423.                 switch (c) {
  424.  
  425.                 /*
  426.                  * The digit 0 is always legal, but is
  427.                  * special.  For %i conversions, if no
  428.                  * digits (zero or nonzero) have been
  429.                  * scanned (only signs), we will have
  430.                  * base==0.  In that case, we should set
  431.                  * it to 8 and enable 0x prefixing.
  432.                  * Also, if we have not scanned zero digits
  433.                  * before this, do not turn off prefixing
  434.                  * (someone else will turn it off if we
  435.                  * have scanned any nonzero digits).
  436.                  */
  437.                 case '0':
  438.                     if (base == 0) {
  439.                         base = 8;
  440.                         flags |= PFXOK;
  441.                     }
  442.                     if (flags & NZDIGITS)
  443.                         flags &= ~(SIGNOK|NZDIGITS|NDIGITS);
  444.                     else
  445.                         flags &= ~(SIGNOK|PFXOK|NDIGITS);
  446.                     goto ok;
  447.  
  448.                 /* 1 through 7 always legal */
  449.                 case '1': case '2': case '3':
  450.                 case '4': case '5': case '6': case '7':
  451.                     base = basefix[base];
  452.                     flags &= ~(SIGNOK | PFXOK | NDIGITS);
  453.                     goto ok;
  454.  
  455.                 /* digits 8 and 9 ok iff decimal or hex */
  456.                 case '8': case '9':
  457.                     base = basefix[base];
  458.                     if (base <= 8)
  459.                         break;    /* not legal here */
  460.                     flags &= ~(SIGNOK | PFXOK | NDIGITS);
  461.                     goto ok;
  462.  
  463.                 /* letters ok iff hex */
  464.                 case 'A': case 'B': case 'C':
  465.                 case 'D': case 'E': case 'F':
  466.                 case 'a': case 'b': case 'c':
  467.                 case 'd': case 'e': case 'f':
  468.                     /* no need to fix base here */
  469.                     if (base <= 10)
  470.                         break;    /* not legal here */
  471.                     flags &= ~(SIGNOK | PFXOK | NDIGITS);
  472.                     goto ok;
  473.  
  474.                 /* sign ok only as first character */
  475.                 case '+': case '-':
  476.                     if (flags & SIGNOK) {
  477.                         flags &= ~SIGNOK;
  478.                         goto ok;
  479.                     }
  480.                     break;
  481.  
  482.                 /* x ok iff flag still set & 2nd char */
  483.                 case 'x': case 'X':
  484.                     if (flags & PFXOK && p == buf + 1) {
  485.                         base = 16;    /* if %i */
  486.                         flags &= ~PFXOK;
  487.                         goto ok;
  488.                     }
  489.                     break;
  490.                 }
  491.  
  492.                 /*
  493.                  * If we got here, c is not a legal character
  494.                  * for a number.  Stop accumulating digits.
  495.                  */
  496.                 break;
  497.         ok:
  498.                 /*
  499.                  * c is legal: store it and look at the next.
  500.                  */
  501.                 *p++ = c;
  502.                 _gptr++;
  503.                 if (sgetc() == EOF)
  504.                     break;        /* EOF */
  505.             }
  506.             /*
  507.              * If we had only a sign, it is no good; push
  508.              * back the sign.  If the number ends in `x',
  509.              * it was [sign] '0' 'x', so push back the x
  510.              * and treat it as [sign] '0'.
  511.              */
  512.             if (flags & NDIGITS) {
  513.                 if (p > buf)
  514.                     (void) sputbackc(*(u_char *)--p);
  515.                 goto match_failure;
  516.             }
  517.             c = ((u_char *)p)[-1];
  518.             if (c == 'x' || c == 'X') {
  519.                 --p;
  520.                 (void) sputbackc(c);
  521.             }
  522.             if ((flags & SUPPRESS) == 0) {
  523.                 u_long res;
  524.  
  525.                 *p = 0;
  526.                 res = (*ccfn)(buf, (char **)NULL, base);
  527.                 if (flags & POINTER)
  528.                     *va_arg(ap, void **) = (void *)res;
  529.                 else if (flags & SHORT)
  530.                     *va_arg(ap, short *) = res;
  531.                 else if (flags & LONG)
  532.                     *va_arg(ap, long *) = res;
  533.                 else
  534.                     *va_arg(ap, int *) = res;
  535.                 nassigned++;
  536.             }
  537.             nread += p - buf;
  538.             break;
  539.  
  540. #ifdef FLOATING_POINT
  541.         case CT_FLOAT:
  542.             /* scan a floating point number as if by strtod */
  543. #ifdef hardway
  544.             if (width == 0 || width > sizeof(buf) - 1)
  545.                 width = sizeof(buf) - 1;
  546. #else
  547.             /* size_t is unsigned, hence this optimisation */
  548.             if (--width > sizeof(buf) - 2)
  549.                 width = sizeof(buf) - 2;
  550.             width++;
  551. #endif
  552.             flags |= SIGNOK | NDIGITS | DPTOK | EXPOK;
  553.             for (p = buf; width; width--) {
  554.                 c = *_gptr;
  555.                 /*
  556.                  * This code mimicks the integer conversion
  557.                  * code, but is much simpler.
  558.                  */
  559.                 switch (c) {
  560.  
  561.                 case '0': case '1': case '2': case '3':
  562.                 case '4': case '5': case '6': case '7':
  563.                 case '8': case '9':
  564.                     flags &= ~(SIGNOK | NDIGITS);
  565.                     goto fok;
  566.  
  567.                 case '+': case '-':
  568.                     if (flags & SIGNOK) {
  569.                         flags &= ~SIGNOK;
  570.                         goto fok;
  571.                     }
  572.                     break;
  573.                 case '.':
  574.                     if (flags & DPTOK) {
  575.                         flags &= ~(SIGNOK | DPTOK);
  576.                         goto fok;
  577.                     }
  578.                     break;
  579.                 case 'e': case 'E':
  580.                     /* no exponent without some digits */
  581.                     if ((flags&(NDIGITS|EXPOK)) == EXPOK) {
  582.                         flags =
  583.                             (flags & ~(EXPOK|DPTOK)) |
  584.                             SIGNOK | NDIGITS;
  585.                         goto fok;
  586.                     }
  587.                     break;
  588.                 }
  589.                 break;
  590.         fok:
  591.                 *p++ = c;
  592.                 _gptr++;
  593.                 if (sgetc() == EOF)
  594.                     break;    /* EOF */
  595.             }
  596.             /*
  597.              * If no digits, might be missing exponent digits
  598.              * (just give back the exponent) or might be missing
  599.              * regular digits, but had sign and/or decimal point.
  600.              */
  601.             if (flags & NDIGITS) {
  602.                 if (flags & EXPOK) {
  603.                     /* no digits at all */
  604.                     while (p > buf)
  605.                         sputbackc(*(u_char *)--p);
  606.                     goto match_failure;
  607.                 }
  608.                 /* just a bad exponent (e and maybe sign) */
  609.                 c = *(u_char *)--p;
  610.                 if (c != 'e' && c != 'E') {
  611.                     (void)sputbackc(c);/* sign */
  612.                     c = *(u_char *)--p;
  613.                 }
  614.                 (void) sputbackc(c);
  615.             }
  616.             if ((flags & SUPPRESS) == 0) {
  617.                 double res;
  618.  
  619.                 *p = 0;
  620.                 res = atof(buf);
  621.                 if (flags & LONG)
  622.                     *va_arg(ap, double *) = res;
  623.                 else
  624.                     *va_arg(ap, float *) = res;
  625.                 nassigned++;
  626.             }
  627.             nread += p - buf;
  628.             break;
  629. #endif /* FLOATING_POINT */
  630.         }
  631.     }
  632. input_failure:
  633.     return (nassigned ? nassigned : -1);
  634. match_failure:
  635.     return (nassigned);
  636. }
  637.  
  638. /*
  639.  * Fill in the given table from the scanset at the given format
  640.  * (just after `[').  Return a pointer to the character past the
  641.  * closing `]'.  The table has a 1 wherever characters should be
  642.  * considered part of the scanset.
  643.  */
  644. static u_char *__sccl(register char *tab, register u_char *fmt)
  645. {
  646.     register int c, n, v;
  647.  
  648.     /* first `clear' the whole table */
  649.     c = *fmt++;        /* first char hat => negated scanset */
  650.     if (c == '^') {
  651.         v = 1;        /* default => accept */
  652.         c = *fmt++;    /* get new first char */
  653.     } else
  654.         v = 0;        /* default => reject */
  655.     /* should probably use memset here */
  656.     for (n = 0; n < 256; n++)
  657.         tab[n] = v;
  658.     if (c == 0)
  659.         return (fmt - 1);/* format ended before closing ] */
  660.  
  661.     /*
  662.      * Now set the entries corresponding to the actual scanset
  663.      * to the opposite of the above.
  664.      *
  665.      * The first character may be ']' (or '-') without being special;
  666.      * the last character may be '-'.
  667.      */
  668.     v = 1 - v;
  669.     for (;;) {
  670.         tab[c] = v;        /* take character c */
  671. doswitch:
  672.         n = *fmt++;        /* and examine the next */
  673.         switch (n) {
  674.  
  675.         case 0:            /* format ended too soon */
  676.             return (fmt - 1);
  677.  
  678.         case '-':
  679.             /*
  680.              * A scanset of the form
  681.              *    [01+-]
  682.              * is defined as `the digit 0, the digit 1,
  683.              * the character +, the character -', but
  684.              * the effect of a scanset such as
  685.              *    [a-zA-Z0-9]
  686.              * is implementation defined.  The V7 Unix
  687.              * scanf treats `a-z' as `the letters a through
  688.              * z', but treats `a-a' as `the letter a, the
  689.              * character -, and the letter a'.
  690.              *
  691.              * For compatibility, the `-' is not considerd
  692.              * to define a range if the character following
  693.              * it is either a close bracket (required by ANSI)
  694.              * or is not numerically greater than the character
  695.              * we just stored in the table (c).
  696.              */
  697.             n = *fmt;
  698.             if (n == ']' || n < c) {
  699.                 c = '-';
  700.                 break;    /* resume the for(;;) */
  701.             }
  702.             fmt++;
  703.             do {        /* fill in the range */
  704.                 tab[++c] = v;
  705.             } while (c < n);
  706. #if 1    /* XXX another disgusting compatibility hack */
  707.             /*
  708.              * Alas, the V7 Unix scanf also treats formats
  709.              * such as [a-c-e] as `the letters a through e'.
  710.              * This too is permitted by the standard....
  711.              */
  712.             goto doswitch;
  713. #else
  714.             c = *fmt++;
  715.             if (c == 0)
  716.                 return (fmt - 1);
  717.             if (c == ']')
  718.                 return (fmt);
  719. #endif
  720.             break;
  721.  
  722.         case ']':        /* end of scanset */
  723.             return (fmt);
  724.  
  725.         default:        /* just another character */
  726.             c = n;
  727.             break;
  728.         }
  729.     }
  730.     /* NOTREACHED */
  731. }
  732.